<template>
  <div class="product-grid">
    <div
        class="product-card"
        v-for="product in products"
        :key="product.id" @click="router.push({path:`/product/details/${product.id}`})">
      <img
          :src="product.cover"
          :alt="product.title"
          class="product-image"
      >
      <div class="product-info">
        <div class="product-title">{{ product.title }}</div>
        <div class="product-price">¥{{ product.price/100 }}</div>
        <div class="product-meta">
          <span>销量: {{ product.sold }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import {useRouter} from "vue-router";

const router = useRouter();

defineProps({
    products: {
      type: Array,
      required: true
    }
  });


</script>

<style scoped>
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}

.product-card {
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  transition: transform 0.3s ease;
}

.product-card:hover {
  transform: translateY(-5px);
}

.product-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.product-info {
  padding: 15px;
}

.product-title {
  font-size: 16px;
  margin-bottom: 10px;
  color: #212529;
  height: 40px;
  overflow: hidden;
}

.product-price {
  color: #e60012;
  font-weight: bold;
  font-size: 18px;
  margin-bottom: 10px;
}

.product-meta {
  display: flex;
  justify-content: space-between;
  color: #6c757d;
  font-size: 14px;
}

@media (max-width: 768px) {
  .product-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
</style>